package com.lzy.cloud.goods.service.carRent.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzy.cloud.goods.dtos.CarRentAppDto;
import com.lzy.cloud.goods.dtos.CarRentDto;
import com.lzy.cloud.goods.entity.CarRent;
import com.lzy.cloud.goods.mapper.CarRentMapperExt;
import com.lzy.cloud.goods.service.carRent.CarRentService;
import com.lzy.framework.core.orm.db.Pager;
import com.lzy.framework.core.utils.DozerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author lc
 * @version 2018/7/12
 */
@Service
public class CarRentServiceImpl implements CarRentService {

    @Autowired
    private CarRentMapperExt carRentMapperExt;

    @Override
    public Long add(CarRentDto carRentDto) {
        CarRent carRent = DozerUtils.map(carRentDto,CarRent.class);
        return carRentMapperExt.insertSelective(carRent)>0?carRent.getId():null;
    }

    @Override
    public PageInfo<CarRentDto> selectList(Pager pager, CarRentDto dto,Integer sortType) {
        if (pager != null)
            PageHelper.startPage(pager.getPageNum(), pager.getPageSize());
        List<CarRentDto> carRentDtos = carRentMapperExt.selectList(dto,sortType);
        return new PageInfo<>(carRentDtos);
    }

    @Override
    public CarRentDto selectById(Long id) {
        return DozerUtils.map(carRentMapperExt.selectByPrimaryKey(id),CarRentDto.class);
    }

    @Override
    public Boolean update(CarRentDto carRentDto) {
        return carRentMapperExt.updateByPrimaryKeySelective(DozerUtils.map(carRentDto,CarRent.class))>0;
    }

    @Override
    public Boolean deleteByKey(Long id) {
        return carRentMapperExt.deleteByPrimaryKey(id)>0;
    }

    @Override
    public Integer getCarNumberByShopId(Long shopId) {
        return carRentMapperExt.getCarNumberByShopId(shopId);
    }

    /**
     * app端分页查询
     * @param pager
     * @param dto
     * @return
     */
    @Override
    public PageInfo<CarRentAppDto> findList(Pager pager, CarRentAppDto dto,Integer sortType) {
        if (pager != null)
            PageHelper.startPage(pager.getPageNum(), pager.getPageSize());
        List<CarRentAppDto> carRentAppDtos = carRentMapperExt.findList(dto,sortType);
        return new PageInfo<>(carRentAppDtos);
    }

    @Override
    public CarRentAppDto findById(Long id) {
        return carRentMapperExt.findById(id);
    }

}
